def info():
    n = input("请输入n：")
    num = int(n[:-2])
    k = int(n[-1])
    a = 0
    while True:
        for i in str(num):
            if i == str(3):
                a += 1
            if a == k:
                return num
                break
        num += 1
        if a != k:
            a = 0


if __name__ == '__main__':
    print(info())
